﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BeanboxSoftware.BeanProxy
{
  public static class TestUtils
  {
    public static void AssertExceptionThrown<T>(Action action) where T : Exception
    {
      AssertExceptionThrown<T>(action, "The wrong exception was thrown");
    }
    public static void AssertExceptionThrown<T>(Action action, string message) where T : Exception
    {
      var actualType = typeof(void);

      try
      {
        action();
      }
      catch (Exception ex)
      {
        actualType = ex.GetType();
      }

      if (actualType == typeof(void))
      {
        throw new ArgumentException("No exception was thrown as expected");
      }

      if (actualType != typeof(T))
      {
        throw new InvalidCastException(message + string.Format("[{0}]!=[{1}]", typeof(T), actualType));
      }
    }
  }
}
